#include "form_shield_dlg.h"
#include "ui_form_shield_dlg.h"


/*
 * Function:    FormShieldDlg
 * Description: The default constructor
 * Paramer:     void
 * Return:
 */
FormShieldDlg::FormShieldDlg(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FormShieldDlg)
{
    qDebug() << Q_FUNC_INFO;

    ui->setupUi(this);
}

/*
 * FormShieldDlg:    ~FormShieldDlg
 * Description: The default destructor
 * Paramer:     void
 * Return:
 */
FormShieldDlg::~FormShieldDlg()
{
    qDebug() << Q_FUNC_INFO;

    delete ui;
}

/*
 * Function:    getInstance
 * Description: Get an instance of "FormShieldDlg" class, if exist, return it
 * Paramer:     QWidget *pParent - the pointer of QWidget class
 * Return:      the pointer of "FormStartupTest" class
 */
FormShieldDlg* FormShieldDlg::getInstance(QWidget *pParent, int nX, int nY)
{
    Q_UNUSED(nX);
    Q_UNUSED(nY);

    static FormShieldDlg *pNew = NULL;
    if(!pNew) {
        qDebug() << Q_FUNC_INFO;

        // Create a new object if it doesn't exist
        pNew = new FormShieldDlg(pParent);
        if(NULL == pNew) return NULL;

        // After constructing object, initialize the object
        pNew->_Initialze();

        // Initialize control's UI
        pNew->_InitUi();

        // Hide widget firstly
        pNew->hide();
    }
    else {
        // Set the parent object
        pNew->setParent(pParent);
    }

//    pNew->move(nX, nY);

    return pNew;
}

/*
 * Function:    _Initialze
 * Description: After constructing object, initialize the object
 * Paramer:     void
 * Return:      void
 */
void FormShieldDlg::_Initialze()
{
    // Signal-slot initialization
    bool bConn = QObject::connect(this, SIGNAL(signalDisplayWindow(bool)), this, SLOT(slotDisplayWindow(bool)));
    Q_ASSERT(bConn);
}

/*
* Function:		_InitUi
* Description:	Init the window style
* Paramer:		void
* Return:		void
*/
void FormShieldDlg::_InitUi()
{
    qDebug() << Q_FUNC_INFO;

    // Displays the background image of the window
    QWidget::setAttribute(Qt::WA_StyledBackground);

    this->setStyleSheet("FormShieldDlg {background-color: rgba(150, 150, 150, 0.5);}");

    // Adjust the position
    this->move(0, 0);
    this->hide();
}

/*
* Function:		changeEvent
* Description:	Triggers an event before it is switch language
* Paramer:		QShowEvent *event - the pointer of "QEvent"
* Return:		void
*/
void FormShieldDlg::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);

    switch (e->type())
    {
    case QEvent::LanguageChange:
        qDebug() << Q_FUNC_INFO;

        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

/*
* Function:		slotDisplayWindow
* Description:	Show or hide the window
* Paramer:		bool bShow - show the window?
* Return:		void
*/
void FormShieldDlg::slotDisplayWindow(bool bShow)
{
    qDebug() << Q_FUNC_INFO << bShow;

    if(bShow) this->show();
    else this->hide();
}

/*
 * Function:    _SetWindowShadow
 * Description: Set Shadow under the window
 * Paramer:     void
 * Return:      void
 */
void FormShieldDlg::_setWindowShadow()
{
    setAutoFillBackground(false);
    setWindowFlags(Qt::Widget | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
    setAttribute(Qt::WA_TranslucentBackground, true);

    if(NULL == m_pShadow) m_pShadow = new QGraphicsDropShadowEffect(this);
    m_pShadow->setOffset(0, 0);
    m_pShadow->setColor(Qt::black);
    m_pShadow->setBlurRadius(20);
    this->setGraphicsEffect(m_pShadow);
    this->setWindowOpacity(1);
}
